//
//  Person
//
//  Created by Caue W. on 2011-03-11.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
package examples.simple;
import time.Types;
import time.Errors;

class Person 
{
	public var birth:NotNull<Date>;
	public var firstName:String;
	public var lastName:String;
	public var rg:String;
	@Default("%NOW")	
	public var lastChanges:Date;
	
	public var father:Person;
	public var mother:Person;
	
	public function new()
	{
		
	}
	
	public function checkDefaults() : Void
	{
		if (birth == null)
			throw ConstraintError.NotNullFieldNotSet("birth");
		if (lastChanges == null)
			lastChanges = Date.now();
	}
	
	public function hxMake(m:Dynamic, prefix:String) : Void
	{
		this.birth = Reflect.field(m, prefix + "birth");
		this.firstName = m.firstName;
		this.lastName = m.lastName;
		this.rg = m.rg;
		this.lastChanges = m.lastChanges;
		this.father = Make(m, prefix + "father$");
		
	}
	
	public function getTypeBuilder() : Dynamic
	{
		return {birth:"Date", firstName:"String", lastName:"String", rg:"String", father:Person.getTypeBuilder(), mother:Person.getTypeBuilder()};
	}
	
}

class Company
{
	public var name:String;
	public var revenue:Int;
	public var country:String;
	
	@Child public var employees:Array<Employee>;
	
	public function new() : Void
	{
		
	}
}

class Employee extends Person
{
	@Parent public var company:Company;
	public var title:String;
	public var jobDescription:String;
}

